package com.company.tx2021;

import java.util.*;

public class Main2 {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<int[]> groups = new ArrayList<>();
        Set<Integer> people = new HashSet<>();
        int index = 0;
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int[] group = new int[x];
            for (int j = 0; j < x; j++) {
                int mark = sc.nextInt();
                if(mark == 0){
                    index = i;
                }
                group[j] = mark;
            }
            groups.add(group);
        }
        int[] containsZero = groups.get(index);
        for (int i = 0; i <containsZero.length; i++) {
            people.add(containsZero[i]);
        }
        for (int i = 0; i < groups.size(); i++) {
            int[] temp = groups.get(i);
            boolean hasPartner = false;
            int j = 0;
            while (j < temp.length){
                if(people.contains(temp[j]) || temp[j] == 0){
                    hasPartner = true;
                    break;
                }
                j++;
            }
            if(hasPartner){
                for (int k = 0; k < temp.length ; k++) {
                    people.add(temp[k]);
                }
            }
        }
        System.out.println(people.size());

    }
}
